class_name SlotBtn
extends TextureButton

#region 属性
@export var normal_color:Color
@export var hover_color:Color
@export var pressed_color:Color
@export var hover_scale:float = 1.06
var menu:CircleBtnMenu
var idx:int = -1
var connect_obj_dict:Dictionary = {}
#endregion
#region 字段
#endregion
#region 信号
#endregion

#region 基类方法
#endregion
#region 公共方法
func init_slot_btn(menu:CircleBtnMenu, idx:int):
	self.menu = menu
	self.idx = idx
	set_icon(null)
	rotation_degrees = idx * 45
	%Icon.rotation_degrees = -idx * 45
func set_icon(texture:Texture2D):
	%Icon.texture = texture
func set_selected(selected:bool):
	%Icon.material.set_shader_parameter("enable",selected)
#endregion
#region 私有方法
func _on_texture_button_pressed() -> void:
	var tween:Tween = create_tween()
	tween.tween_property(self,"self_modulate",pressed_color,0.1)
	tween.tween_property(self,"self_modulate",hover_color if is_hovered() else normal_color,0.1)
	menu.btn_pressed.emit(idx)
func _on_mouse_entered() -> void:
	var tween:Tween = create_tween()
	tween.tween_property(self,"self_modulate",hover_color,0.1)
	tween.parallel()
	tween.tween_property(self,"scale",Vector2(hover_scale,hover_scale),0.1)
func _on_mouse_exited() -> void:
	var tween:Tween = create_tween()
	tween.tween_property(self,"self_modulate",normal_color,0.1)
	tween.parallel()
	tween.tween_property(self,"scale",Vector2.ONE, 0.1)
#endregion
#region 生命周期函数
func _init() -> void:
	connect_obj_dict["Pressed"] = ConnectObj.new(pressed,[_on_texture_button_pressed])
	connect_obj_dict["MouseEntered"] = ConnectObj.new(pressed,[_on_mouse_entered])
	connect_obj_dict["MouseExited"] = ConnectObj.new(pressed,[_on_mouse_exited])
func _enter_tree() -> void:
	self_modulate = normal_color
func _notification(what: int) -> void:
	if what == NOTIFICATION_PREDELETE:
		for obj:ConnectObj in connect_obj_dict.values():
			obj.disconnect_all()
#endregion
